package domain;

import java.io.Serializable;
import java.math.BigDecimal;

public class Product implements Serializable {

    private static final long serialVersionUID = -7492639752670189553L;
    private final String SRC_PREFIX = "<a href=\"ProductForm?productId=";
    private String SRC_POSTFIX = "class=\"small_img\" data-id=\"";
    private String curType = "small";
    private String productId;
    private String species;
    private String breed;
    private BigDecimal unitprice;
    private String descr;
    private String imageSrc;
    private boolean srcFix = false;

    public Product() {
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getSpecies() {
        return species;
    }

    public void setSpecies(String species) {
        this.species = species;
    }

    public String getBreed() {
        return breed;
    }

    public void setBreed(String breed) {
        this.breed = breed;
    }

    public BigDecimal getUnitprice() {
        return unitprice;
    }

    public void setUnitprice(BigDecimal unitprice) {
        this.unitprice = unitprice;
    }

    public String getDescr() {
        return descr;
    }

    public void setDescr(String descr) {
        this.descr = descr;
    }

    public String getImageSrc() {
        if(srcFix){
            return imageSrc;
        }
        return SRC_PREFIX + productId + imageSrc + SRC_POSTFIX + productId + "\"/></a>";
    }

    public void setImageSrc(String imageSrc) {
        this.imageSrc = imageSrc;
        srcFix = imageSrc.startsWith("href", 3);
        if(srcFix){
            this.imageSrc = imageSrc.replace("big", curType);
        }
    }

    public void setImageSize(String type){
        if(srcFix){
            imageSrc = imageSrc.replace(curType, type);
            curType = type;
            return;
        }
        SRC_POSTFIX = SRC_POSTFIX.replace(curType, type);
        curType = type;
    }
}
